#!/bin/bash

set -e

if [ -n "$DEBUG" ];then
    set -x
    PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # print line number and function name
fi

if [ -z "$(which shasum)" ]; then
    echo "Checksum utility 'shasum' not found."
    exit 1
fi

. script/bootstrap

mkdir -p bin
bindir="$PWD"/bin
scriptdir="$PWD"/script

# We have a few binaries that we want to build, so let's put them into bin/

version=$(git rev-parse HEAD)
describe=$(git describe --tags --always --dirty)

export GOPATH="$PWD/.gopath"
cd .gopath/src/github.com/openark/orchestrator

# We put the binaries directly into the bindir, because we have no need for shim wrappers
go build -i -o "$bindir/orchestrator" -ldflags "-X main.AppVersion=${version} -X main.BuildDescribe=${describe}" ./go/cmd/orchestrator/main.go

rsync -qa ./resources $bindir/
